#!/bin/bash
#============================================================================
#MCSM Installation Script
#By: jingwenMC
#============================================================================
#Args:
#-i [folder] -- Install Dir. , Default is /mcsm
#-y -- No Interaction
#============================================================================
#WARNING:PLEASE FOLLOW THE ARGUMENTS RULE OR THE SCRIPT MAY CAUSE SOME ERRORS
#============================================================================

Skip="0"
Output="mcsm_log.log"
Dir="/mcsm"

while [ $# -ge 1 ] ; do
    case "$1" in
        -i) Dir=$2; shift 2;;
        -y) Skip="1" ; shift 1;;
        *) echo "Error:Unknown Argument $1." ; exit 1 ; break;;
    esac
done

if [ "$Skip" -eq "0" ]
then
    echo "===================================================================="
    echo "MCSM Installation Script"
    echo "By: jingwenMC"
    echo "===================================================================="
    echo "Installing MCSM Panel to dir:"$Dir
    echo ""
    echo "We will not install Java Runtime"
    echo ""
    echo "Are You Sure? [y/n/...]"
    echo "===================================================================="
    read Sure
    if [ "$Sure" != "y" ]
    then
        echo "MCSM Panel installation canceled."
        exit 0
    fi
fi

mkdir $Dir
cd $Dir

#CentOS:
yum install -y wget git 

#Ubuntu:
#apt install -y wget git 

wget https://npm.taobao.org/mirrors/node/v12.16.1/node-v12.16.1-linux-x64.tar.gz
tar -zxvf node-v12.16.1-linux-x64.tar.gz
ln -s ~/node-v12.16.1-linux-x64/bin/node /usr/bin/node
ln -s ~/node-v12.16.1-linux-x64/bin/npm /usr/bin/npm
node -v
git clone https://github.com/suwings/mcsmanager.git
cd mcsmanager/
npm install
echo "Installation Complete."